/**
  netcdf-utils.c - Created by Timothy Morey on 5/22/2012
*/

#include <netcdf.h>
#include <stdio.h>
#include <string.h>

#include "err.h"
#include "logger.h"
#include "netcdf-utils.h"

#ifdef __WINDOWS__
#pragma warning(disable:4996)
#endif

int GetTypeSize(int type, size_t* size)
{
  int retval = NVN_NOERR;

  if(size)
  {
    switch((nc_type)type)
    {
      case NC_BYTE:
      case NC_CHAR:
        *size = 1;
        break;

      case NC_SHORT:
        *size = 2;
        break;

      case NC_INT:
      case NC_FLOAT:
        *size = 4;
        break;

      case NC_DOUBLE:
        *size = 8;
        break;

      default:
        retval = NVN_EINVTYPE;
        break;
    }
  }
  else
  {
    retval = NVN_EINVARGS;
  }

  return retval;
}

int PrintNetCDFError(const char* msg, int err)
{
  int retval = NVN_NOERR;
  char logmsg[256];
  
  sprintf(logmsg, "NetCDF Error %d: %s", err, msg);
  WriteMessage(LogLevelError, logmsg);

  return retval;
}